#include <bits/stdc++.h>
using namespace std;


typedef pair<int, int> pii;
int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    int T; cin >> T;
    while(T--){
        int N, P; cin >> N >> P;
        list<pii> l;
        for (int i = 0; i < N; ++i) {
            int t; cin >> t;
            pii tmp = make_pair(t, 0);
            if(i == P) tmp.second = 1;
            l.push_back(tmp);
        }
        int ans = 0;
        while(true){
            int mx = -1; auto it = l.begin();
            for (auto i = l.begin();  i!= l.end(); i++) {
                if((*i).first > mx) {
                    mx = (*i).first;
                    it = i;
                }
            }
            l.splice(l.end(), l, l.begin(), it);
            ++ans;
            if(l.front().second == 1) break;
            l.erase(l.begin());
        }
        cout << ans << "\n";
    }
    return 0;
}